package com.nft.service.school.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nft.service.school.entity.UserBookDetailEntity;
import com.nft.service.school.resp.UserBookDetailResp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
@DS("master")
public interface UserBooksDetailMapper extends BaseMapper<UserBookDetailEntity> {
    @Select("select id,file_url,jxcontent,create_time from user_books_detail "+
            "where userbook_id=#{userbookId} and content_id=#{contentId} and contentd_id=#{qid}")
    public List<UserBookDetailResp> getBookDetailByBId(@Param("userbookId")Long userbookId, @Param("contentId")Long contentId, @Param("qid")Long qid);

    @Select("SELECT b.id, b.userbook_id, b.content_id, b.contentd_id, b.file_url, b.jxcontent, b.create_time, b.status " +
            "FROM user_books a left join user_books_detail b on b.userbook_id=a.id " +
            "where a.task_id=#{taskId} and a.user_id=#{userId}")
    public List<UserBookDetailResp> getErrorDetailByUserId(@Param("taskId")Long taskId, @Param("userId")Long userId);

    @Select("SELECT b.id, b.userbook_id, b.content_id, b.contentd_id, b.file_url, b.jxcontent, b.create_time, b.status " +
            "FROM user_books a left join user_books_detail b on b.userbook_id=a.id " +
            "where a.task_id=#{taskId} and a.user_id=#{userId} and b.status=#{status}")
    public List<UserBookDetailResp> getErrorDetailByUserIdStatus(@Param("taskId")Long taskId, @Param("userId")Long userId, @Param("status")String status);
}
